﻿Public Class Form_Entry_Edit_Data_Arsip
    Inherits System.Web.UI.Page
    Dim koneksidataakses11 As New KoneksiDataAkses
    Dim kueri As String

    Sub bersih()
        textbox1.Text = ""
        textbox2.Text = ""
        textbox3.Text = ""
        textbox4.Text = ""
        textbox5.Text = ""
        GridView1.SelectedIndex = -1
        dropdownlist1.DataBind()
        dropdownlist2.DataBind()
        dropdownlist3.DataBind()
        dropdownlist4.DataBind()
        dropdownlist5.DataBind()
    End Sub
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        tabel1.Visible = False
    End Sub

    Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand
        If e.CommandName = "btnCopy" Then
            bersih()
            textbox1.Text = GridView1.Rows(e.CommandArgument.ToString).Cells(4).Text
            textbox2.Text = GridView1.Rows(e.CommandArgument.ToString).Cells(5).Text
            textbox3.Text = GridView1.Rows(e.CommandArgument.ToString).Cells(2).Text
            textbox4.Text = GridView1.Rows(e.CommandArgument.ToString).Cells(6).Text
            textbox5.Text = GridView1.Rows(e.CommandArgument.ToString).Cells(3).Text
            'If GridView1.Rows(e.CommandArgument.ToString).Cells(3).Text = "Aktif" Then
            '    dropdownlist1.SelectedValue = 0
            'ElseIf GridView1.Rows(e.CommandArgument.ToString).Cells(3).Text = "Pasif" Then
            '    dropdownlist1.SelectedValue = 1
            'End If
            dropdownlist1.Text = GridView1.Rows(e.CommandArgument.ToString).Cells(0).Text
            dropdownlist2.Text = GridView1.Rows(e.CommandArgument.ToString).Cells(1).Text
            dropdownlist3.Text = GridView1.Rows(e.CommandArgument.ToString).Cells(7).Text
            dropdownlist4.Text = GridView1.Rows(e.CommandArgument.ToString).Cells(8).Text
            dropdownlist5.Text = GridView1.Rows(e.CommandArgument.ToString).Cells(10).Text

            System.Web.HttpContext.Current.Session("status_action") = True
            tabel1.Visible = True
        End If
    End Sub


    Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles GridView1.SelectedIndexChanged
        textbox1.Text = GridView1.SelectedRow.Cells(4).Text
        textbox2.Text = GridView1.SelectedRow.Cells(5).Text
        textbox3.Text = GridView1.SelectedRow.Cells(2).Text
        textbox4.Text = GridView1.SelectedRow.Cells(6).Text
        textbox5.Text = GridView1.SelectedRow.Cells(3).Text
        'If GridView1.Rows(e.CommandArgument.ToString).Cells(3).Text = "Aktif" Then
        '    dropdownlist1.SelectedValue = 0
        'ElseIf GridView1.Rows(e.CommandArgument.ToString).Cells(3).Text = "Pasif" Then
        '    dropdownlist1.SelectedValue = 1
        'End If
        dropdownlist1.Text = GridView1.SelectedRow.Cells(0).Text
        dropdownlist2.Text = GridView1.SelectedRow.Cells(1).Text
        dropdownlist3.Text = GridView1.SelectedRow.Cells(7).Text
        dropdownlist4.Text = GridView1.SelectedRow.Cells(8).Text
        dropdownlist5.Text = GridView1.SelectedRow.Cells(10).Text
        System.Web.HttpContext.Current.Session("status_action") = False

        tabel1.Visible = True

    End Sub


    Protected Sub Button3_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button3.Click
        System.Web.HttpContext.Current.Session("status_action") = True
        tabel1.Visible = True
    End Sub

    Protected Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles button1.Click
        'kueri = "insert into TB_SKA_ARSIP (id_klasifikasi,id_unit,perihal,keyword,tahun,jangka_retensi,jumlah_dok,actual_jumlah_dok,id_kontainer,id_lokasi,id_status,id_jenis_arsip,tgl_entry,id_pengentry,is_valid,is_relocated,is_destroyed)values ((select id_klasifikasi from TB_MST_KLASIFIKASI where kode_klasifikasi='" + dropdownlist1.Text + "'),(select id_unit from tb_mst_unit where kode_unit = '" + dropdownlist2.Text + "'),'" + textbox3.Text + "','" + textbox5.Text + "'," + textbox1.Text + "," + textbox2.Text + "," + textbox4.Text + ",2,(select id_kontainer from TB_MST_KONTAINER where kode_kontainer='" + dropdownlist3.Text + "'),(select id_lokasi from TB_MST_LOKASI where kode_lokasi='" + dropdownlist4.Text + "'),1,(select id_jenis_arsip from TB_MST_JENIS_ARSIP where jenis_arsip='" + dropdownlist5.Text + "'),CURRENT_TIMESTAMP,1,0,0,0)"
        'kueri = "update TB_SKA_ARSIP set id_klasifikasi=(select id_klasifikasi from TB_MST_KLASIFIKASI where kode_klasifikasi='" + dropdownlist1.Text + "'),id_unit=(select id_unit from TB_MST_UNIT where kode_unit='" + dropdownlist2.Text + "'),perihal='" + textbox3.Text + "',keyword='" + textbox5.Text + "',tahun=" + textbox1.Text + ",jangka_retensi=" + textbox2.Text + ",jumlah_dok=" + textbox4.Text + ",id_kontainer=(select id_kontainer from TB_MST_KONTAINER where kode_kontainer='" + dropdownlist3.Text + "'), id_lokasi=(select id_lokasi from TB_MST_LOKASI where kode_lokasi='" + dropdownlist4.Text + "'),id_jenis_arsip=(select id_jenis_arsip from TB_MST_JENIS_ARSIP where jenis_arsip='" + dropdownlist5.Text + "')"
        'koneksidataakses11.EksekusiNonQuery(kueri)
        'GridView1.DataBind()
        'bersih()

        If Session("status_action") = True Then
            kueri = "insert into TB_SKA_ARSIP (id_klasifikasi,id_divisi,perihal,keyword,tahun,jangka_retensi,jumlah_dok,actual_jumlah_dok,id_kontainer,id_lokasi,id_status,id_jenis_arsip,tgl_entry,id_pengentry,is_valid,is_relocated,is_destroyed)values ((select id_klasifikasi from TB_MST_KLASIFIKASI where kode_klasifikasi='" + dropdownlist1.Text + "'),(select id_divisi from tb_mst_divisi where kode_divisi = '" + dropdownlist2.Text + "'),'" + textbox3.Text + "','" + textbox5.Text + "'," + textbox1.Text + "," + textbox2.Text + "," + textbox4.Text + ",2,(select id_kontainer from TB_MST_KONTAINER where kode_kontainer='" + dropdownlist3.Text + "'),(select id_lokasi from TB_MST_LOKASI where kode_lokasi='" + dropdownlist4.Text + "'),1,(select id_jenis_arsip from TB_MST_JENIS_ARSIP where jenis_arsip='" + dropdownlist5.Text + "'),CURRENT_TIMESTAMP,1,0,0,0)"
            koneksidataakses11.EksekusiNonQuery(kueri)
            GridView1.DataBind()
            bersih()
        ElseIf Session("status_action") = False Then
            kueri = "update TB_SKA_ARSIP set id_klasifikasi=(select id_klasifikasi from TB_MST_KLASIFIKASI where kode_klasifikasi='" + dropdownlist1.Text + "'),id_divisi=(select id_divisi from TB_MST_DIVISI where kode_divisi='" + dropdownlist2.Text + "'),perihal='" + textbox3.Text + "',keyword='" + textbox5.Text + "',tahun=" + textbox1.Text + ",jangka_retensi=" + textbox2.Text + ",jumlah_dok=" + textbox4.Text + ",id_kontainer=(select id_kontainer from TB_MST_KONTAINER where kode_kontainer='" + dropdownlist3.Text + "'), id_lokasi=(select id_lokasi from TB_MST_LOKASI where kode_lokasi='" + dropdownlist4.Text + "'),id_jenis_arsip=(select id_jenis_arsip from TB_MST_JENIS_ARSIP where jenis_arsip='" + dropdownlist5.Text + "') WHERE id_arsip = " + GridView1.SelectedRow.Cells(18).Text + ""
            koneksidataakses11.EksekusiNonQuery(kueri)
            GridView1.DataBind()
            bersih()
        End If
    End Sub

    Protected Sub button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles button2.Click
        bersih()
        tabel1.Visible = False
    End Sub

    Protected Sub GridView1_PageIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles GridView1.PageIndexChanged
        bersih()
    End Sub


End Class